<template>
  <div class="layout-container">
    <el-container>
      <el-header>
        <el-row :gutter="20">
          <el-col :span="6">
            <div class="logo"></div>
          </el-col>
          <el-col :span="6" :offset="12" style="text-align:right">
            <el-button type="primary" @click="logout" round>安全退出</el-button>
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <el-aside :width="asideWidth">
          <!-- 折叠带单的按钮 -->
          <div class="menu-toggle" @click="toggle">
            |||
          </div>
          <!-- :default-openeds="['1', '3']" -->
          <el-menu
            background-color="#001529"
            text-color="#fff"
            active-text-color="#ffd04b"
            :collapse="!isCollapse"
            class="el-menu-vertical-demo"
            :width="asideWidth"
          >
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-s-goods"></i>
                商品管理
              </template>
              <el-menu-item index="1-1" @click="$router.push({path:'/product-list'})">
                  商品列表
              </el-menu-item>
              <el-menu-item index="1-2">
                  新增商品
              </el-menu-item>
            </el-submenu>

            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-s-data"></i>
                数据统计
              </template>
              <el-menu-item index="2-1" @click="$router.push({path:'/charts-bar'})">柱状图</el-menu-item>
              <el-menu-item index="2-2" @click="$router.push({path:'/charts-pie'})">饼状图</el-menu-item>
              <el-menu-item index="2-3" @click="$router.push({path:'/charts-line'})">折线图</el-menu-item>
            </el-submenu>
          </el-menu>


        </el-aside>
        <el-main>
          <!-- 路由占位符 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: true
    };
  },
  computed: {
    asideWidth() {
      return this.isCollapse ? "200px" : "65px";
    }
  },
  methods: {
    toggle() {
      this.isCollapse = !this.isCollapse;
    },
    // 安全退出
    logout() {
      // 1-清空本地存储中的登录凭证
      sessionStorage.removeItem("token");
      // 2-重定向到登录页面
      this.$router.push("/login");
    }
  }
};
</script>

<style scoped lang="less">
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.layout-container {
  height: 100%;
  .el-header {
    background-color: #001529;
    color: #fff;
    text-align: center;
    line-height: 60px;
    .logo {
      margin-top: 8px;
      width: 200px;
      height: 60px;
      background: url("../assets/logo.png") no-repeat;
      background-size: contain;
    }
  }
  .el-aside {
    background-color: #001529;
    color: #333;
    text-align: center;
    .el-menu {
      border: 0;
    }
    .menu-toggle {
      color: #fff;
      font-size: 14px;
      text-align: center;
      line-height: 25px;
      background-color: #4a5064;
      user-select: none;
      cursor: pointer;
      letter-spacing: 0.1em;
    }
  }
  .el-container {
    height: 100%;
  }
  .el-main {
    background-color: #e9eef3;
    color: #333;
  }
}

body > .el-container {
  margin-bottom: 40px;
}

</style>